package cn.edu.hqu.wel.shiyan2.service.impl;

import cn.edu.hqu.wel.shiyan2.mapper.ProductMapper;
import cn.edu.hqu.wel.shiyan2.model.Product;
import cn.edu.hqu.wel.shiyan2.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    private final ProductMapper productMapper;

    @Autowired
    public ProductServiceImpl(ProductMapper productMapper) {
        this.productMapper = productMapper;
    }

    @Override
    public List<Product> getAllProducts() {
        return productMapper.selectList(null);
    }

    @Override
    public Product getProductById(Long id) {
        return productMapper.selectById(id);
    }

    @Override
    public Product createProduct(Product product) {
        productMapper.insert(product);
        return product;
    }

    @Override
    public Product updateProduct(Product product) {
        productMapper.updateById(product);
        return product;
    }

    @Override
    public void deleteProduct(Long id) {
        productMapper.deleteById(id);
    }
}
